/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Negocio;

import DAO.Data;
import gui.MWRibbon;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.jdesktop.swingx.JXBusyLabel;
import org.prevayler.Prevayler;
import org.prevayler.PrevaylerFactory;

    
/**
 *
 * @author jeferson
 */
public class BackupDownload implements Runnable{
    
    private String dir;
    private JXBusyLabel bl;
    private Prevayler prev;
    private ArrayList<Aluno> alunos;
    private MWRibbon mwr;
    
    public BackupDownload(String dir, JXBusyLabel bl, ArrayList<Aluno> alunos, MWRibbon mwr) {
        this.dir = dir;
        this.bl = bl;
        this.alunos = alunos;
        this.mwr = mwr;
        bl.setText("Carregando Dados");
    }
 
    @Override
    public void run() {
        bl.setBusy(true);
        PrevaylerFactory factory = new PrevaylerFactory();
        factory.configurePrevalenceDirectory(dir);
        factory.configurePrevalentSystem(new Data());
        try {
            prev = factory.create();
            Data d = ((Data) prev.prevalentSystem());
            /*for (Aluno a : d.getArrayAlunos()) {
                mwr.addAluno(a);
            }*/
            mwr.addAlunos(d.getArrayAlunos());
            mwr.carregaDados();
            bl.setBusy(false);
            bl.setText("");
            JOptionPane.showMessageDialog(mwr, "Dados Carregados com sucesso!");
        } catch (IOException ex) {
            Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(mwr, "Problema na carga dos dados");
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MWRibbon.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(mwr, "Problema na carga dos dados");
        }
    }
}
